#include "utils.h"
#include <assert.h>


std::string serializeForAEA(AppendEntriesArgs& myStruct) {
    nlohmann::json j = myStruct;
    return j.dump();
}
std::string serializeForAER(AppendEntriesReply& myStruct) {
    nlohmann::json j = myStruct;
    return j.dump();
}
std::string serializeForVA(VoteArgs& myStruct) {
    nlohmann::json j = myStruct;
    return j.dump();
}
std::string serializeForVR(VoteReply& myStruct) {
    nlohmann::json j = myStruct;
    return j.dump();
}
AppendEntriesArgs deserializeForAEA(std::string& serializedData) {
    nlohmann::json j = nlohmann::json::parse(serializedData);
    return j.get<AppendEntriesArgs>();
}
AppendEntriesReply deserializeForAER(std::string& serializedData) {
    nlohmann::json j = nlohmann::json::parse(serializedData);
    return j.get<AppendEntriesReply>();
}
VoteArgs deserializeForVA(std::string& serializedData) {
    nlohmann::json j = nlohmann::json::parse(serializedData);
    return j.get<VoteArgs>();
}
VoteReply deserializeForVR(std::string& serializedData) {
    nlohmann::json j = nlohmann::json::parse(serializedData);
    return j.get<VoteReply>();
}

std::string requestTypeToString(RequestType type) {
    switch (type) {
        case RequestType::AppendEntriesArgs:
            return "AppendEntriesArgs";
        case RequestType::AppendEntriesReply:
            return "AppendEntriesReply";
        case RequestType::VoteArgs:
            return "VoteArgs";
        case RequestType::VoteReply:    
            return "VoteReply";
        default:
            return "Unknown";
    }

}